import 'package:flutter_repository/annotations/repository.dart';
import 'package:flutter_repository/repository/base_repository.dart';
import 'package:flutter_repository/repository/request_state.dart';
import 'package:get/get.dart';
import 'package:example_app/api/wan_api.dart';
import 'package:example_app/mapper/home_data_mapper.dart';
import 'package:example_app/model/banner_model.dart';
import 'package:example_app/model/popular_site_model.dart';
import 'package:example_app/model/top_article_model.dart';
import 'package:example_app/repository/repository.dart';
part 'wan_repository.g.dart';

@Repo()
abstract class WanRepository extends BaseRepository {
  late WanApi wanApi = GetInstance().find();

  ///获取首页所需的所有数据
  @ProxyCall()
  @Retry()
  Stream<Resource<HomeDataMapper>> homeData() async* {
    // final BannerModel banner = await wanApi.getBanner();
    // final TopArticleModel article = await wanApi.getTopArticle();
    // final PopularSiteModel site = await wanApi.getPopularSite();
    var result = await Future.wait<dynamic>(
        [wanApi.getBanner(), wanApi.getPopularSite(), wanApi.getTopArticle()]);
    final BannerModel banner = result[0];
    final PopularSiteModel site = result[1];
    final TopArticleModel article = result[2];
    yield Resource.success(
        HomeDataMapper(site.data, banner.data, article.data));
  }
}
